package org.kev.transit.util;

import org.punit.runner.SoloRunner; 
import junit.framework.TestCase;
import java.io.IOException;
import java.util.*;
import org.apache.commons.httpclient.HttpException;
import org.json.JSONException;
import org.kev.transit.data.*;

/**
 * JUnit test case.  These test cases can be run outside of the emulator or phone.
 * Good for test web connection , utility functions 
 * @author kevin
 *
 */
public class TransitTest extends TestCase{
	
/*	public void testStopWebService() throws HttpException, IOException{
		String jsonTest=WebHelper.getStop("1", "1", "1");
	}
	public void testStopJsonParse() throws HttpException, IOException, JSONException{
		String jsonText=WebHelper.getStop("1", "1", "1");
		ArrayList <Stop> list=JsonHelper.getStops(jsonText);
		assertTrue("returned nothing!",list.size()>0);
		Stop stop=list.get(1);
		assertTrue("is not a stop dat obj!",stop!=null);
		assertTrue("stop.title=null",stop.title!=null);
	}*/
	public void testTimeTableWebService() throws HttpException, IOException{
		String jsonTest=WebHelper.getTimeTable("3", "2", "1","1");
		assertTrue(" text is null="+jsonTest!=null  );
	}
/**
 * 
 * @throws HttpException
 * @throws IOException
 * @throws JSONException
 */
	public void testTimeTableJsonParse() throws HttpException, IOException, JSONException{
		String jsonText=WebHelper.getTimeTable("3", "2", "3","2");
		ArrayList <TimeTable> list=JsonHelper.getTimeTables(jsonText);
		assertTrue("returned nothing!",list.size()>0);
		TimeTable data=list.get(0);
		//data.time
		System.out.println("time="+data.time);
		assertTrue("has time data ",data.time!=null);
		String id= data.id;
		String s=data.stopId;
		String r = data.route;
		String rt=data.routeType;
		String d =data.direction;


		assertTrue("rtype!=3 ="+rt,rt!=null && rt.equals("3"));
		assertTrue("route!=2 ="+r,r!=null && r.equals("2"));
		assertTrue("dir!=2 ="+d,d!=null && d.equals("3"));
		assertTrue("stop!=2 ="+s,s!=null && s.equals("2"));
		assertTrue("rtype!=3 ="+id,id!=null );		
	}
	
	/**
	 * 
	 * @throws HttpException
	 * @throws IOException
	 */
	public void testDirectionWebService() throws HttpException, IOException{
		String jsonTest=WebHelper.getDirection("1", "1");
		assertTrue(" text is null="+jsonTest!=null  );
	}
	
	/**
	 * 
	 * @throws HttpException
	 * @throws IOException
	 * @throws JSONException
	 */
	public void testDirectionJsonParse() throws HttpException, IOException, JSONException{
		String jsonText=WebHelper.getDirection("3", "2");
		//System.out.println("jsonText="+jsonText);
		ArrayList <Direction> list=JsonHelper.getDirections(jsonText);
		assertTrue("returned nothing!",list.size()>0);
		Direction data=list.get(1);
		assertTrue("is not a dat obj!",data!=null);
		String rt=data.routeType;
		assertTrue("rtype is null",rt!=null);
		String r=data.route;
		System.out.println("r="+r);
		assertTrue("route not =2 route="+rt,rt!=null && rt.equals("3") );
		assertTrue("route not =3 route="+r,r!=null && r.equals("2") );

		
	}
	
	/**
	 * 
	 * @throws HttpException
	 * @throws IOException
	 */
	public void testRouteService() throws HttpException, IOException{
		String jsonTest=WebHelper.getRoute("1");
		assertTrue(" text is null="+jsonTest!=null  );
	}
	
	/**
	 * 
	 * @throws HttpException
	 * @throws IOException
	 * @throws JSONException
	 */
	public void testRouteJasonParse() throws HttpException, IOException, JSONException{
		String jsonText=WebHelper.getRoute("2");
		ArrayList <Route> list=JsonHelper.getRoutes(jsonText);
		assertTrue("returned nothing!",list.size()>0);
		Route data=list.get(0);
		assertTrue("is not a Route  data obj!",data!=null);
		String rt= data.routeType;
		System.out.println("rt="+rt);
		assertTrue("routType not =2 rtype="+rt,rt!=null && rt.equals("2") );
		
	}
	/**
	 * 
	 * @throws HttpException
	 * @throws IOException
	 * @throws JSONException
	 */
	public void testStopData() throws HttpException, IOException, JSONException{
		String jsonText=WebHelper.getStop("2", "3","2");
		ArrayList <Stop> list=JsonHelper.getStops(jsonText);
		assertTrue("returned nothing!",list.size()>0);
		Stop data=list.get(0);
		assertTrue("is not a stop dat obj!",data!=null);
		String rt= data.routeTypeId;
		String r=data.routeId;
		String d=data.directionId;	
		assertTrue("rtype=!2 ="+rt,rt!=null && rt.equals("2"));
		assertTrue("rtype=!3 ="+r,r!=null && r.equals("3"));
		assertTrue("rtype=!2 ="+d,d!=null && d.equals("2"));		
	}
	/**
	 * 
	 * @throws HttpException
	 * @throws IOException
	 */
	public void testRouteTypeService() throws HttpException, IOException{
		String jsonTest=WebHelper.getRouteType();
		assertTrue(" text is null="+jsonTest!=null  );
	}
	
	/**
	 * 
	 * @throws HttpException
	 * @throws IOException
	 * @throws JSONException
	 */
	public void testRouteJasonTypeParse() throws HttpException, IOException, JSONException{
		String jsonText=WebHelper.getRouteType();
		ArrayList <RouteType> list=JsonHelper.getRouteTypes(jsonText);
		assertTrue("returned nothing!",list.size()>0);
		RouteType data=list.get(1);
		assertTrue("is not a stop dat obj!",data!=null);
	}
	
	/*
	public void testSettingsService() throws HttpException, IOException{
		String jsonTest=WebHelper.getTimeTable("1", "1", "1","1");
	}*/
	/*
	public void testSettingsParse() throws HttpException, IOException, JSONException{
		String jsonText=WebHelper.getTimeTable("1", "1", "1","1");
		ArrayList <TimeTable> list=JsonHelper.getTimeTables(jsonText);
		assertTrue("returned nothing!",list.size()>0);
		TimeTable data=list.get(1);
		assertTrue("is not a stop dat obj!",data!=null);
	}*/

	/**
	 * 
	 */
    public static void main(String[] args) {
    	SoloRunner runner = new SoloRunner(); //.run(org.kev.transit.TransitTest.class);
    	runner.run(org.kev.transit.util.TransitTest.class);
     } 	
}
